{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load icons %}
{% block title %}{% trans "Instances" %} - {{ compute.name }}{% endblock %}
{% block style %}
<link rel="stylesheet" href="{% static "css/sortable-theme-bootstrap.css" %}" />
{% endblock %}

{% comment %} 







{% block page_heading %}{{ compute.name }} - {% trans "Instances" %}{% endblock page_heading %}

{% block page_heading_extra %}
<a href="{% url 'instances:create_instance_select_type' compute.id %}"
    class="btn btn-success btn-header float-end">
    {% icon 'plus' %}
</a>
{% if instances %}
    {% include 'search_block.html' %}
{% endif %}
{% endblock page_heading_extra %} {% endcomment %}

{% block content %}
<div class="page-wrapper">
    <div class="page-header d-print-none">
        <div class="container-xl">
            <div class="row g-2 align-items-center">
                <div class="col">
                    <div class="page-pretitle">
                        Instances
                    </div>
                    <h2 class="page-title">
                        {{ compute.name }}
                    </h2>
                </div>
            </div>
        </div>
    </div>

    <!-- Page body -->
    <div class="page-body">
        <div class="container-xl">
            <div class="card">
                <div class="card-header">
                    <ul class="nav nav-tabs card-header-tabs">
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'overview' compute.id %}">
                            <span>{% icon 'dashboard' %}&nbsp;&nbsp;{% trans "Overview" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                        <a class="nav-link active" href="#">
                            <span  class="text-azure">{% icon 'server' %}&nbsp;&nbsp;{% trans "Instances" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'storages' compute.id %}">
                                <span>{% icon 'hdd-o' %}&nbsp;&nbsp;{% trans "Storages" %}</span>
                            </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'networks' compute.id %}">
                                    <span>{% icon 'sitemap' %}&nbsp;&nbsp;{% trans "Networks" %}</span>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'interfaces' compute.id %}">
                                    <span>{% icon 'wifi' %}&nbsp;&nbsp;{% trans "Interfaces" %}</span>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'nwfilters' compute.id %}">
                                    <span>{% icon 'filter' %}&nbsp;&nbsp;{% trans "NWFilters" %}</span>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'virtsecrets' compute.id %}">
                                    <span>{% icon 'key' %}&nbsp;&nbsp;{% trans "Secrets" %}</span>
                                </a>
                            </li>
                        <li class="nav-item ms-auto">
                        <a class="nav-link" href="{% url 'instances:create_instance_select_type' compute.id %}">
                            <span class="text-blue">
                                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-device-desktop-plus" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                    <path d="M13.5 16h-9.5a1 1 0 0 1 -1 -1v-10a1 1 0 0 1 1 -1h16a1 1 0 0 1 1 1v7.5"></path>
                                    <path d="M7 20h5"></path>
                                    <path d="M9 16v4"></path>
                                    <path d="M16 19h6"></path>
                                    <path d="M19 16v6"></path>
                                </svg>
                            </span>
                        </a>
                        </li>
                    </ul>
                </div>
                <div class="card-body">
                    <p class="text-muted">
                        <!-- Tab1 -->
                        <div class="col-lg-12">
                            {% if not instances %}
                                <div class="alert alert-warning shadow-sm fade show">
                                    {% icon 'exclamation-triangle' %} <strong>{% trans "Warning" %}:</strong>
                                    {% trans "Hypervisor doesn't have any Instances" %}
                                </div>
                            </div>
                            {% else %}
                                <table class="table table-hover sortable-theme-bootstrap" data-sortable>
                                    <thead>
                                        <tr>
                                            {% comment %} <th><button class="table-sort" data-sort="sort-name">{% trans 'Name' %}</button></th> {% endcomment %}
                                            <th scope="col">{% trans 'Name' %}</th>
                                            <th scope="col">{% trans 'User' %}</th>
                                            <th scope="col">{% trans 'Status' %}</th>
                                            <th scope="col">{% trans 'VCPU' %}</th>
                                            <th scope="col">{% trans 'Memory' %}</th>
                                            <th scope="col" data-sortable="false">{% trans 'Actions' %}</th>
                                        </tr>
                                    </thead>
                                    <tbody class="searchable">
                                        {% for instance in instances  %}
                                        <tr>
                                            <td>
                                                <a class="link-primary" href="{% url 'instances:instance' instance.id %}">{{ instance.name }}</a>
                                                <br>
                                                <p class="m-0 small fst-italic">{{ instance.title }}</p>
                                            </td>
                                            <td>
                                                <em>
                                                    {% if instance.userinstance_set.all.count > 0 %}
                                                    {{ instance.userinstance_set.all.0.user }}
                                                    {% if instance.userinstance_set.all.count > 1 %}
                                                    (+{{ instance.userinstance_set.all.count|add:"-1" }})
                                                    {% endif %}
                                                    {% endif %}
                                                </em>
                                            </td>
                                            <td>
                                                {% if instance.proxy.instance.info.0 == 1 %}<span
                                                    class="text-success">{% trans "Active" %}</span>{% endif %}
                                                {% if instance.proxy.instance.info.0 == 5 %}<span
                                                    class="text-danger">{% trans "Off" %}</span>{% endif %}
                                                {% if instance.proxy.instance.info.0 == 3 %}<span
                                                    class="text-warning">{% trans "Suspended" %}</span>{% endif %}
                                            </td>
                                            <td>{{ instance.proxy.instance.info.3 }}</td>
                                            <td>{% widthratio instance.proxy.instance.info.1 1024 1 %} MiB</td>
                                            <td class="text-nowrap">
                                                {% include 'instance_actions.html' %}
                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            {% endif %}
                        </div>



                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block script %}
    <script src="{% static 'assets/js/sortable.min.js' %}"></script>
    <script src="{% static 'assets/js/filter-table.js' %}"></script>
{% endblock %}